﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetNuke;
using DotNetNuke.Data;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
namespace TwentyTech.ToolTips
{
    /// <summary>
    /// Summary description for ToolTipHandler
    /// </summary>
    public class ToolTipHandler : IHttpHandler
    {


        private int ModuleID
        {
            get;
            set;
        }
        private PortalSettings PortalSettings
        {
            get { return Globals.GetPortalSettings(); }
        }

        private HttpRequest Request
        {
            get;
            set;
        }
        private HttpResponse Response
        {
            get;
            set;
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            Request = context.Request;
            Response = context.Response;

            ModuleID = Request.Form["moduleId"]!=null ? Convert.ToInt32(Request.Form["moduleId"].ToString()) : 0;
            //if (Request.Form["moduleId"] != null)
            //{
            //    ModuleID = Convert.ToInt32(Request.Form["moduleId"]);
            //}
            switch(Request.Form["method"])
            {
                case "updatecontent":
                    ToolTipController.SaveContent(ModuleID, Request.Form["content"].ToString());
                    Response.Write(JsonExtensionsWeb.ToJson("Success"));
                    break;
                case "addtooltip":
                    int tooltipid = ToolTipController.AddToolTip(ModuleID, Request.Form["content"].ToString());
                    Response.Write(JsonExtensionsWeb.ToJson(tooltipid));
                    break;
                case "updatetooltip":
                    ToolTipController.UpdateToolTip(Convert.ToInt32(Request.Form["tooltipId"]),ModuleID, Request.Form["content"].ToString());
                    Response.Write(JsonExtensionsWeb.ToJson("Success"));
                    break;
                case "deletetooltip":
                    ToolTipController.DeleteToolTip(Convert.ToInt32(Request.Form["tooltipId"]));
                    Response.Write(JsonExtensionsWeb.ToJson("Success"));
                    break;
                default:
                    break;
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}